1109A - Sasha and a Bit of Relax - CodeForces Solution


dp implementation *1600

Please click on ads to support us..

C++ Code:

// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define  PI              3.141592653589793238462
#define mset(x,val)     memset(x,val,sizeof(x))
#define  f               first
#define  s               second
#define  pb             push_back
#define  mp             make_pair
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"deb1\n";
#define  deb2(a,b)       cout<<a<<" deb2 "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" deb3 "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" deb4 "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD       =  1e+9 + 7;
const ll   mod        =  1e+9 + 7 ;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

/*---------------------------------------------------------------------------------------------------------------------------*/

ll madd(ll a, ll b) { return (a + b) % mod;}
ll msub(ll a, ll b) {return (((a - b) % mod) + mod) % mod;}
ll mmul(ll a, ll b) {return ((a % mod) * (b % mod)) % mod;}
ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp) {
        if (exp % 2 == 1) {
            res = (res * base) % mod;
        }
        exp >>= 1;
        base = (base * base) % mod;
    }
    return res;
}
ll minv(ll base) {return mpow(base, mod - 2);}
ll mdiv(ll a, ll b) {return mmul(a, minv(b));}

/*---------------------------------------------------------------------------------------------------------------------------*/

void MAIN(ll tc)
{
    ll n; cin >> n;
    vector<ll> vec(n + 1);
    map<ll, ll> mpe, mpo;
    ll ans = 0, x = 0;
    mpe[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        cin >> vec[i];
        x = x ^ vec[i];

        if (i % 2 == 1)
        {
            ans += mpo[x];
            mpo[x]++;
        }
        else
        {
            ans += mpe[x];
            mpe[x]++;
        }
        debug(i)
        debug(ans)
    }

    cout << ans;


}


int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
#endif
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    fastio();
    cout << fixed << setprecision(15);

    int test__cases = 1;
    // cin >> test__cases;
    for (int i = 1; i <= test__cases; i++) {
        MAIN(i);
        cout << "\n";
    }

#ifndef ONLINE_JUDGE
    cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs " << endl;
#endif

}



Comments

Submit
0 Comments
More Questions

1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers
1174A - Ehab Fails to Be Thanos
1169A - Circle Metro
780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)